package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
//权限管理Service实现类
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionDao permissionDao;
    //分页查询
    @Override
    public PageResult findByPermission(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<Permission> page = permissionDao.findByPermission(queryString);
        long total = page.getTotal();
        List<Permission> result = page.getResult();
        PageResult pageResult = new PageResult(total, result);
        return pageResult;
    }
    //权限添加
    @Override
    public void add(Permission permission){
        permissionDao.add(permission);
    }
    //根据id查询权限对象
    @Override
    public Permission findUpdate(int id) {
        Permission permission = permissionDao.findUpdate(id);
        return permission;
    }
    //修改权限
    @Override
    public void updateEdit(Permission permission) {
        permissionDao.updateEdit(permission);
    }
    //根据id删除权限
    @Override
    public void delete(int id) {
        permissionDao.delete_role(id);
        permissionDao.delete(id);
    }
}
